/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.opgea.crm.domain.entities;

import com.opgea.crm.common.constant.ApplicationConstant;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


import com.opgea.crm.domain.entities.security.CrmUser;

/**
 *
 * @author Admin
 */
	@Entity
	@Table(name = "lead")
	@NamedQueries({
	@NamedQuery(name = "Lead.findAll", query = "SELECT l FROM Lead l")})
    public class Lead implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "prefix")
    private Integer prefix;
    @Column(name = "firstName", length = 45)
    private String firstName;
    @Column(name = "middleInitial", length = 1)
    private String middleInitial;
    @Column(name = "lastName", length = 45)
    private String lastName;
    @Column(name = "suffix", length = 12)
    private String suffix;
    @Column(name = "title", length = 45)
    private String title;
    
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "leadStatus")
    private ApplicationConstant.LeadStatusQualifier leadStatus;
    
    @Enumerated(EnumType.ORDINAL)
    @Column(name="activeStatus")
    private ApplicationConstant.ActiveQualifier activeStatus;
    
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @ManyToOne( cascade={CascadeType.MERGE, CascadeType.PERSIST})
    private Company company;
    

    @OneToOne(cascade = {CascadeType.ALL}, mappedBy = "lead",fetch=FetchType.EAGER)
    private Leadprofile leadprofile;
    
    
    @OneToMany(mappedBy = "lead", cascade = CascadeType.ALL)
    private Collection<Leadphones> leadphonesCollection;
    
    @OneToMany(mappedBy = "relatedContact", cascade = CascadeType.ALL)
    private Collection<Opportunity> opportunityCollection;
    
    /*
    @OneToMany(mappedBy = "lead", cascade = CascadeType.ALL)
    private Collection<Leademails> leademailsCollection;
    */
    
    @OneToOne(mappedBy = "lead", cascade = CascadeType.ALL)
    private Leademails leademail;
    
    @OneToMany(mappedBy = "lead", cascade = CascadeType.ALL)
    private Collection<Activity> activityCollection;

    @OneToMany(mappedBy = "lead", cascade = CascadeType.ALL)
    private List<AdditionalContact> additionalContacts;
    
    @OneToMany(mappedBy = "lead" ,cascade={CascadeType.MERGE, CascadeType.PERSIST})
    private List<LeadDocuments> documents;
    
	@OneToMany(cascade=CascadeType.ALL, mappedBy="customer")
	private List<ProjectDetails> projects;
	
	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="createdBy", referencedColumnName="username")
	private CrmUser createdBy;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="createdat")
	private Date createdAt;
    
    public Lead() {
    }

    public Lead(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getPrefix() {
        return prefix;
    }

    public void setPrefix(Integer prefix) {
        this.prefix = prefix;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getMiddleInitial() {
        return middleInitial;
    }

    public void setMiddleInitial(String middleInitial) {
        this.middleInitial = middleInitial;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    /*
    public void setLeadStatus(Integer leadStatus) {
		this.leadStatus = leadStatus;
	}

	public Integer getLeadStatus() {
		return leadStatus;
	}
	*/

	public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public void setLeadprofile(Leadprofile leadprofile) {
		this.leadprofile = leadprofile;
	}

	public Leadprofile getLeadprofile() {
		return leadprofile;
	}

    public Collection<Leadphones> getLeadphonesCollection() {
        return leadphonesCollection;
    }

    public void setLeadphonesCollection(Collection<Leadphones> leadphonesCollection) {
        this.leadphonesCollection = leadphonesCollection;
    }

    public Collection<Opportunity> getOpportunityCollection() {
        return opportunityCollection;
    }

    public void setOpportunityCollection(Collection<Opportunity> opportunityCollection) {
        this.opportunityCollection = opportunityCollection;
    }

    public void setLeademail(Leademails leademail) {
		this.leademail = leademail;
	}

	public Leademails getLeademail() {
		return leademail;
	}

	/*
	public Collection<Leademails> getLeademailsCollection() {
        return leademailsCollection;
    }

    public void setLeademailsCollection(Collection<Leademails> leademailsCollection) {
        this.leademailsCollection = leademailsCollection;
    }
    */

    public Collection<Activity> getActivityCollection() {
        return activityCollection;
    }

    public void setActivityCollection(Collection<Activity> activityCollection) {
        this.activityCollection = activityCollection;
    }

  
	
	
	public ApplicationConstant.LeadStatusQualifier getLeadStatus() {
		return leadStatus;
	}

	public void setLeadStatus(ApplicationConstant.LeadStatusQualifier leadStatus) {
		this.leadStatus = leadStatus;
	}

	public ApplicationConstant.ActiveQualifier getActiveStatus() {
		return activeStatus;
	}

	public void setActiveStatus(ApplicationConstant.ActiveQualifier activeStatus) {
		this.activeStatus = activeStatus;
	}

	public List<AdditionalContact> getAdditionalContacts() {
		return additionalContacts;
	}

	public void setAdditionalContacts(List<AdditionalContact> additionalContacts) {
		this.additionalContacts = additionalContacts;
	}

	public void setDocuments(List<LeadDocuments> documents) {
		this.documents = documents;
	}

	public List<LeadDocuments> getDocuments() {
		return documents;
	}

	public void setProjects(List<ProjectDetails> projects) {
		this.projects = projects;
	}

	public List<ProjectDetails> getProjects() {
		return projects;
	}

	public void setCreatedBy(CrmUser createdBy) {
		this.createdBy = createdBy;
	}

	public CrmUser getCreatedBy() {
		return createdBy;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	@Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Lead)) {
            return false;
        }
        Lead other = (Lead) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.crm.domain.Lead[id=" + id + "]";
    }

}
